/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>			                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#ifndef __MATHCONSTANTS_H__
#define __MATHCONSTANTS_H__

#include <math.h>
#include "../../Types/Types.h"

#define PI				3.141592653589793238462f
#define TWOPI			6.283185307179586476924f


/// Power.
template <typename T>
inline T Power(const T &A, const T &B) {
	return (T) pow((cDouble) A, (cDouble) B);
}

/// Abs.
template <typename T>
inline T Abs(const T &A) {
	if (A < 0) {
		return -A;
	} else {
		return A;
	}
}

/// Square.
template <typename T>
inline T Sqr(const T &A) {
	return A * A;
}

/// Square root.
template <typename T>
inline T Sqrt(const T &A) {
	return T(sqrt(A));
}

/// Floor.
template <typename T>
inline cInt Floor(const T &Value) {
	return cInt(floor(Value));
}

/// Ceiling.
template <typename T>
inline cInt Ceiling(const T &Value) {
	return cInt(ceilf(Value));
}

/// Min.
template <typename T>
inline T Min(const T &Value1, const T &Value2) {
	return (Value1 < Value2) ? Value1 : Value2;
}

/// Max.
template <typename T>
inline T Max(const T &Value1, const T &Value2) {
	return (Value1 > Value2) ? Value1 : Value2;
}

class MathConstants {
private:
	cFloat mSin[360];
	cFloat mCos[360];

public:
	
	/**************************************************************
	* Constructors                                                *
	***************************************************************/
	MathConstants() { 
		for (cInt i = 0; i < 360; i++) {
			*(mSin + i) = sinf((PI * ((cFloat) i) / 180.0f));
			*(mCos + i) = cosf((PI * ((cFloat) i) / 180.0f));
		}
	}

	/**************************************************************
	* Other halpful functions                                     *
	***************************************************************/
	inline cFloat GetSin(const cInt& fDegree) {
		return *(mSin + (fDegree % 360));
	}

	inline cFloat GetCos(const cInt& fDegree) {
		return *(mCos + (fDegree % 360));
	}
};

#endif // __MATHCONSTANTS_H__

